﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WinFormsAppTest.Dao;
using WinFormsAppTest.Service;

namespace WinFormsAppTest.Control
{
    public partial class UserChangeSearchControl : UserControl
    {
        private int userid;
        public UserChangeSearchControl()
        {
            InitializeComponent();
        }

        public UserChangeSearchControl(int id)
        {
            userid = id;
            InitializeComponent();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            timelabel.Text = DateTime.Now.ToString("G");
        }

        private void SearchControl_Load(object sender, EventArgs e)
        {
            //调整时间控件
            timer1.Interval = 1000;
            timer1.Start();
            //

            //调整界面的大小使得所有的控件显示出来
            this.Size = new Size(1029, 501);
            //

            //开始添加表格中的数据
            //FormService formservice = new FormService();
            //FilesdataGridView = formservice.Form_Changesdata_Loading(FilesdataGridView);
            DataGridViewClass dataGridViewClass = new DataGridViewClass();
            FilesdataGridView = dataGridViewClass.GetChangeDataByUserId(FilesdataGridView, userid);
            //
        }

        private void UserdataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            //判断单元格类型是否为按钮
            if (FilesdataGridView.Columns[e.ColumnIndex] is DataGridViewButtonColumn && e.RowIndex >= 0)
            {
                //获取按钮所在列的名字
                string columnName = FilesdataGridView.Columns[e.ColumnIndex].Name;
                //获取按钮的一整行
                DataGridViewRow row = FilesdataGridView.Rows[e.RowIndex];
                //由于row.Cells["IntColumnName"].Value得到的取值为object型 需要用该方法进行转换
                int changeid = Convert.ToInt32(row.Cells["ChangeIdColumn"].Value);
                string type = Convert.ToString(row.Cells["TypeColumn"].Value);
                DateTime time = Convert.ToDateTime(row.Cells["TimeColumn"].Value);
                int userid = Convert.ToInt32(row.Cells["UserIdColumn"].Value);
                if (columnName == "UpdateColumn")
                {
                    //MessageBox.Show("更新" + userid + " " + name + " " + password);
                    this.Hide();
                    ChangeUpdateForm f = new ChangeUpdateForm(changeid, type, time, userid, "", 0);
                    f.ShowDialog();
                    this.Dispose();

                }
            }
        }

        //private void searchtextBox_Enter(object sender, EventArgs e)
        //{
        //    if (searchtextBox.Text == "请输入搜索内容")
        //        searchtextBox.Text = "";
        //    searchtextBox.ForeColor = Color.Black;
        //}

        //private void searchtextBox_Leave(object sender, EventArgs e)
        //{
        //    if (searchtextBox.Text == "")
        //    {
        //        searchtextBox.Text = "请输入搜索内容";
        //        searchtextBox.ForeColor = Color.Gray;
        //    }
        //}

        //private void searchbutton_Click(object sender, EventArgs e)
        //{
        //    if (string.IsNullOrWhiteSpace(searchtextBox.Text)
        //       || searchcomboBox.SelectedItem == null)//判断复选框是否选中
        //    {
        //        FilesdataGridView.Rows.Clear();
        //        DataGridViewClass dataGridView = new DataGridViewClass();
        //        FilesdataGridView = dataGridView.GetChangeDataByUserId(FilesdataGridView, userid);
        //    }
        //    else
        //    {
        //        string combox = searchcomboBox.SelectedItem.ToString();
        //        FilesdataGridView.Rows.Clear();
        //        //if (int.TryParse(searchtextBox.Text, out int number)
        //        //    && combox == "变动编号")
        //        //{
        //        //    if (number != 0 && searchtextBox.Text != "请输入搜索内容")
        //        //    {
        //        //        DataGridViewClass dataGridView = new DataGridViewClass();
        //        //        FilesdataGridView = dataGridView.GetChangeDataById(FilesdataGridView, number);
        //        //    }
        //        //    else
        //        //    {
        //        //        DataGridViewClass dataGridView = new DataGridViewClass();
        //        //        FilesdataGridView = dataGridView.GetChangesData(FilesdataGridView);
        //        //    }

        //        //}
        //        //else 
        //        if (combox == "变动类型")
        //        {
        //            if (searchtextBox.Text != "" && searchtextBox.Text != "请输入搜索内容")
        //            {
        //                DataGridViewClass dataGridView = new DataGridViewClass();
        //                FilesdataGridView = dataGridView.GetChangeDataByType(FilesdataGridView, searchtextBox.Text);
        //            }
        //            else
        //            {
        //                DataGridViewClass dataGridView = new DataGridViewClass();
        //                FilesdataGridView = dataGridView.GetChangeDataByUserId(FilesdataGridView, userid);
        //            }

        //        }
        //        //else if (combox == "员工编号")
        //        //{
        //        //    if (number != 0 && searchtextBox.Text != "请输入搜索内容")
        //        //    {
        //        //        //MessageBox.Show(""+number);
        //        //        DataGridViewClass dataGridView = new DataGridViewClass();
        //        //        FilesdataGridView = dataGridView.GetChangeDataByUserId(FilesdataGridView, number);
        //        //    }
        //        //    else
        //        //    {
        //        //        DataGridViewClass dataGridView = new DataGridViewClass();
        //        //        FilesdataGridView = dataGridView.GetChangesData(FilesdataGridView);
        //        //    }

        //        //}
        //        //else
        //        //{
        //        //    DataGridViewClass dataGridView = new DataGridViewClass();
        //        //    FilesdataGridView = dataGridView.GetChangesData(FilesdataGridView);
        //        //}
        //    }
        //}
    }
}
